<template>
  <div  class="news-template-side">
      <h4  class="news-template-side-title">{{title}}</h4>
      <ul  class="news-template-side-menus">
        <div  class="new-template-side-menu-group">
          <li  class="news-template-side-menu cursor" v-for="(item ,item_index) in menus"  :key="item_index" @click="link_to(item)">
            <span  class="news-template__point">
              <span  :class="['news-circle', 'inline-block',item.type==activeIndex?'background-primary':'background-grey']"></span> 
            </span>
            <span  :class="['news-template-side-menu-title',item.type==activeIndex?'text-color-primary':'']">{{item.title}}</span>
          </li>
        </div>
      </ul>
    </div>
</template>
<script>
  import Bus from '../../src/bus.js';
  export default {
    props: ['menus','title'],
    data() {
      return {
        activeIndex:-1,
        path:'',
      }
    },
    mounted() {
      Bus.$on('update_activeIndex', () => {
        this.set_all_activeIndex();
      })
      //this.set_all_activeIndex();

    },
    methods:{
      set_all_activeIndex(){
        let path="";
        if(this.title=="平台介绍"){
          path=this.GetLastRoute(this.$route.path);
        }
        else if(this.title=="新闻资讯"){
          path=this.GetLastRoute(this.$route.path);
          if(path=='newsList'){//newsList根目录 什么都不要动

          }
          else if(path=='list'){//platform/newsList/notic?trend?media/list
            path=this.GetLastRoute(this.$route.path,1);
            this.set_activeIndex(path);
          }
          else {//detail http://192.168.31.129:8080/platform/newsList/notic/detail/5e9005902a033029b13fbff9
            let detail=this.GetLastRoute(this.$route.path,1);
            if(detail=="detail"){
              path=this.GetLastRoute(this.$route.path,2);
              this.set_activeIndex(path);
            }
            
          }
        }
        else if(this.title=="服务资源"){
          path=this.GetLastRoute(this.$route.path);
          if(path=='wfs'){
            this.activeIndex=0
          }
          else if(path=='codes'){
            this.activeIndex=1
          }
          else if(path=='props')
          {
            this.activeIndex=2
          }
        }else if(this.title=="后台管理"){
          path=this.GetLastRoute(this.$route.path);
          if(path=='addnews'){
            this.activeIndex=0
          }
          else if(path=='editnews'){
            this.activeIndex=1
          }
          else if(path=='editprops'){
            this.activeIndex=2
          }
          else if(path=='editpois'){
            this.activeIndex=3
          }
        }
        else if(this.title=="GEO动态"){
          path=this.GetLastRoute(this.$route.path);
        }
      },


      set_activeIndex(path){
        if(path=="notic"){
            this.activeIndex=0
          }
          else if(path=="trend"){
            this.activeIndex=1
          }
          else if(path=="media"){
            this.activeIndex=5
          }
          else if(path=="change"){
            this.activeIndex=10
          }
      },
      link_to(item,first=0){
        this.activeIndex=item.type;
          this.emit(item);
          //replace
          this.$router.push({
            path: item.fullroute,
          })
      },
      emit(item){
        if(this.title=="平台介绍"){
          Bus.$emit('news_template_side_click',item.route); //route,type
        }
        else if(this.title=="新闻资讯"){
          Bus.$emit('newsType_change',item);
        }
      }
    }
    
  }
</script>